package com.example.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.Base.BasePersonActivity;
import com.example.administrator.olddoctor.R;
import com.example.tools.StringUtils;

import static com.example.Base.BaseContent.DESCRIBE;
import static com.example.Base.BaseContent.EDITPERSONAL_DESCRIBE_RESULTCODE;
import static com.example.Base.BaseContent.NULL;

/**
 *  描述
 */
public class EditPersonalDescribeActivity extends BasePersonActivity implements View.OnClickListener,TextWatcher{

    private EditText editText;
    private Button ok_button_personal;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_personal_describe);
        init();
        initBundle();
    }

    private void init() {
        setActionBar(getResources().getDrawable(R.mipmap.call_back), null,"个人描述",null,null,null);
        editText = (EditText) findViewById(R.id.text);ok_button_personal = (Button) findViewById(R.id.ok_button_personal);
        ok_button_personal.setOnClickListener(this);getActionBarRightText().setOnClickListener(this);
        getActionBarLeft().setOnClickListener(this);editText.addTextChangedListener(this);
    }

    private void initBundle() {
        String name = getIntent().getExtras().getString(DESCRIBE);
        if(!NULL.equals(name)){
            editText.setText(name);
        }
    }

    @Override
    public void onClick(View view) {
      switch (view.getId()){

          case R.id.actionbar_left:
              showToast("点击了返回");
              break;

          case R.id.ok_button_personal:
              String describe = editText.getText().toString();
              if(StringUtils.isSpace(describe)){
                  showToast("您不能输入空的描述");
              } else {
                  Bundle bundle = new Bundle();
                  bundle .putString(DESCRIBE,describe);
                  setResult(EDITPERSONAL_DESCRIBE_RESULTCODE,new Intent().putExtras(bundle));
                  finish();
              }
              break;
      }
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        String text = s.toString();
        if(text.length()>0){
            ok_button_personal.setEnabled(true);
        } else {
            ok_button_personal.setEnabled(false);
        }
    }

    @Override
    public void afterTextChanged(Editable s) {

    }
}
